﻿@model AddSupplierModel
@{
    ViewBag.Title = "信息编辑";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new AddSupplierModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form id="S_Form" action="@Url.Action("sellerEdit", "supplier")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" style="width:50%">
                <h5>基本信息 <em>* 手机邮箱必填一项</em></h5>
                <input type="hidden" value="@viewModel.aDZ_SupplierMaster.supplier_id" name="aDZ_SupplierMaster.supplier_id" id="aDZ_SupplierMaster.supplier_id" />
                <input type="hidden" value="@viewModel.aDZ_SupplierMaster.supplier_id" name="aDZ_SupplierDetails.supplier_id" id="aDZ_SupplierDetails.supplier_id" />
                <input type="hidden" value="@viewModel.aDZ_SupplierMaster.is_del" name="aDZ_SupplierMaster.is_del" id="aDZ_SupplierMaster.is_del" />
                <input type="hidden" value="@viewModel.aDZ_SupplierMaster.status" name="aDZ_SupplierMaster.status" id="aDZ_SupplierMaster.status" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">供应商公司名称 <em>*</em></td>
            <td>
                <input type="text" name="aDZ_SupplierMaster.supplier_name" id="aDZ_SupplierMaster.supplier_name" style="width:300px;" value="@Model.aDZ_SupplierMaster.supplier_name" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">联系人姓名<em>*</em></td>
            <td>
                <input type="text" name="aDZ_SupplierMaster.contact_name" id="aDZ_SupplierMaster.contact_name" style="width:300px;" value="@Model.aDZ_SupplierMaster.contact_name" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft"> 电子邮箱</td>
            <td>
                <input type="text" id="aDZ_SupplierMaster.email" name="aDZ_SupplierMaster.email" style="width:300px;" value="@Model.aDZ_SupplierMaster.email" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">所在省市<em>*</em></td>
            <td>
                @{
                    var CityInfo1 = new CityInfoViewModel
                    {
                        DivID = "cityidaa1",
                        CityIDFormName = "aDZ_SupplierMaster.cityId",
                        CityNameFormName = "aDZ_SupplierMaster.city_name",
                        ShowDeep = 3,
                        CityID = @Model.aDZ_SupplierMaster.cityId,
                        CityName = @Model.aDZ_SupplierMaster.city_name
                    };
                }
                @{Html.RenderPartial(Url.Content("~/Views/Common/CitySelect.cshtml"), CityInfo1);}
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">详细地址<em>*</em></td>
            <td>
                <input type="text" name="aDZ_SupplierMaster.supplier_address" style="width:300px;" value="@Model.aDZ_SupplierMaster.supplier_address" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">供应商类型<em>*</em></td>
            <td>
                <select id="aDZ_SupplierMaster.supplier_type" name="aDZ_SupplierMaster.supplier_type">
                    @{
                        dc = new Dictionary<string, string>();
                        var list = dbcontext.ADZ_SupplierType.ToList();
                        foreach (var item in list)
                        {
                            dc.Add(item.supplier_type.ToString(), item.supplier_type_name);
                        }
                    }
                    @HtmlPagerHelper.ShowSelectOpton(dc, Model.aDZ_SupplierMaster.supplier_type.ToString());
                </select>&nbsp;
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">QQ</td>
            <td>
                <input type="text" name="aDZ_SupplierMaster.qq" style="width:300px;" value="@Model.aDZ_SupplierMaster.qq" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">手机号码</td>
            <td>
                <input type="text" id="aDZ_SupplierMaster.telephone" name="aDZ_SupplierMaster.telephone" style="width:300px;" value="@Model.aDZ_SupplierMaster.telephone" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">营业执照<em>*</em></td>
            <td>
                <div id="oldimg" style="display:none">
                    <a href="javascript:void(0)" onclick="showimg('@ImageFileBiz.GetImg(Model.aDZ_SupplierMaster.zhizhao_url)')"><img src=" @ImageFileBiz.GetImg(Model.aDZ_SupplierMaster.zhizhao_url, "small")" alt=""></a>
                    <br />
                    <input name="aDZ_SupplierMaster.zhizhao_url" type="hidden" value="@Model.aDZ_SupplierMaster.zhizhao_url" />
                    <button type="button" name="delimg" class="btn btn-primary table-bordered delimg" param-imgkey="@Model.aDZ_SupplierMaster.zhizhao_url">删除此图</button>
                </div>
                <div id="newimg">
                    <img src="" alt="" id="inputFileSrc1" style="width:400px" />
                    <a href="javascript:;" class="a-upload" id="inputFileSrc1_btn">
                        <input type="file" name="file" onchange="handleFiles(this.files,'inputFileSrc1')" accept="image/*">
                    </a>
                </div>
                <script>
                    $(document).ready(function () {
                        if ($("input[name='aDZ_SupplierMaster.supplier_id']").val() > 0) {
                            $("#oldimg").show();
                            $("#newimg").hide();

                            if ($("#oldimg") !== undefined) {
                                $("#newimg").hide();
                            }
                        }

                        $('.delimg').click(function () {
                            deleteParentElement(this);
                            $("#newimg").show();
                        });
                    });
                </script>
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <label>@Model.aDZ_SupplierMaster.remark</label>
                <span id="spMsg"></span>
                @if (viewModel.aDZ_SupplierMaster.status != 5)
                {
                    <button type="submit" class="btn btn-primary">编辑</button>
                }
            </td>
        </tr>
    </table>
</form>
<script>
    BUI.use('bui/form', function (Form) {
        $(function () {
            jQuery.validator.addMethod("isEmailAndTelphone", function (value, element) {
                var emailv = $('#aDZ_SupplierMaster.email').val();
                var telephonev = $('#aDZ_SupplierMaster.telephone').val();
                return (emailv != "") || (telephonev != "");
            }, "邮箱和手机必填一项");


            var validator = $('form').validate({
                errorLabelContainer: $("#errorContainer"),
                errorElement: "span",
                rules: {
                    'aDZ_SupplierMaster.contact_name': { required: true },
                    'aDZ_SupplierMaster.supplier_name': { required: true },
                    'aDZ_SupplierMaster.email': { isEmailAndTelphone: true },
                    'aDZ_SupplierMaster.telephone': { isEmailAndTelphone: true, isMobile: true },
                    'aDZ_SupplierMaster.supplier_address': { required: true },
                    'aDZ_SupplierMaster.cityId': { required: true }
                },
                messages: {
                    'aDZ_SupplierMaster.contact_name': { required: "请输入联系人姓名" },
                    'aDZ_SupplierMaster.supplier_name': { required: "请输入供应商名称" },
                    'aDZ_SupplierMaster.supplier_address': { required: '请输入详细地址' },
                },
                submitHandler: function (form) {
                    $(form).ajaxSubmit(function (result) {
                        ShowActionResult(result);
                    });
                }
            });
        });
    });
</script>